package cn.tedu.boot61.controller;

import cn.tedu.boot61.vo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

@RestController
public class UserController {
    @RequestMapping("/login")
    public int login(User user, String rem, HttpServletResponse response){
        System.out.println("user = " + user + ", rem = " + rem);
        //模拟登录成功
        if(user.getUsername().equals("tom") && user.getPassword().equals("123456")){
            if(rem!=null){
                Cookie c1 = new Cookie("username", user.getUsername());
                Cookie c2 = new Cookie("password", user.getPassword());
                //把cookie下发给客户端(保存在客户端)
                response.addCookie(c1);
                response.addCookie(c2);
            }
            return 1;
        }
        return 2;
    }
}
